#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<unistd.h>
#include <fcntl.h>
#include<sys/socket.h>
#include<arpa/inet.h>


// #define PORT 3333

int main(int argc,char **argv){

   // char serverip[] = "172.27.151.152";
   char serverip[] = "127.0.0.1";
   char PORT[] = "3333";
   // int PORT = 3333;
   struct sockaddr_in server_addr,client_addr;
   socklen_t client_sock_len;

   int sfd = socket(AF_INET,SOCK_STREAM,0);
   server_addr.sin_family = AF_INET;
   // server_addr.sin_port = htons(PORT);
   server_addr.sin_port = htons(atoi(PORT));
   server_addr.sin_addr.s_addr = inet_addr(serverip);

   bind(sfd,(struct sockaddr *)&server_addr,sizeof(server_addr));
   listen(sfd,1024);
   printf(" 服务器准备好: %s 端口是：%s \n",serverip,PORT);
   fflush(NULL);
   
   int clientfd = accept(sfd,(struct sockaddr *)&client_addr,&client_sock_len);
char sersay[1024] = "hello you success connect server\n";

   send(clientfd,sersay,sizeof(sersay),0);
   for (size_t i = 0; i < 3; i++)
   {
      memset(&sersay,0,sizeof(sersay));
      recv(clientfd, &sersay,sizeof(sersay),0);
      printf(" 服务器收到信息： %s \n",sersay);
      memset(&sersay,0,sizeof(sersay));
      sprintf(sersay,"%s%ld","send to client message ",i);
      send(clientfd,sersay,sizeof(sersay), 0 );
      
   }
   

   close(sfd);




   



   return 0;
}